package cn.lintcode;

import java.util.List;

/**
 * @author labvi
 * @version 1.0.0
 * 寻找主元素
 */
public class MajorityEle {
    public int majorityNumber(List<Integer> nums) {
        int count = 0,major = 0;
        for (Integer num : nums) {
            if (0 == count) {
                major = num;
            }
            if (major == num) {
                count++;
            } else {
                count--;
            }
        }
        return major;
    }
}
